const install = (Vue, vm) => {
	// 首页
	const index = (params = {}) => vm.$u.get('/api/index', params); //首页数据

	// 认证相关的
	const authLogin = params => vm.$u.post('/api/auth/login', params); //登录
	const register = params => vm.$u.post('/api/auth/register', params); //注册
	const loginOut = () => vm.$u.post('/api/auth/logout') //退出登录
	const authOss = () => vm.$u.get('/api/auth/oss/token') //获取阿里云oss token认证

	// 用户信息
	const userInfo = params => vm.$u.get('/api/user', params); //获取用户喜喜
	const userChange = params => vm.$u.put('/api/user', params); //修改用户信息
	const userAvatar = params => vm.$u.post('/api/user/avatar', params); //更新头像

	// 商品相关
	const goodsDetail = id => vm.$u.get('/api/goods/' + id) //获取商品详情
	const goodsCollect = id => vm.$u.post('/api/collects/goods/' + id) //收藏和取消
	const goodsList = params => vm.$u.get('/api/goods', params) //获取商品页商品


	// 购物车信息
	const cartList = params => vm.$u.get('/api/carts/', params) //获取购物车列表
	const addCart = params => vm.$u.post('/api/carts', params) //添加购物车
	const changeCheck = params => vm.$u.patch('/api/carts/checked', params) //购物车改变选中
	const removeCart = params => vm.$u.delete('/api/carts/' + params) //移除购物车

	// 订单信息
	const viewCart = () => vm.$u.get('/api/orders/preview'); //订单预览
	const subCart = params => vm.$u.post('/api/orders', params); //提交订单
	const pay = (id, params) => vm.$u.get(`/api/orders/${id}/pay`, params) //获取支付二维码
	const payStatus = id => vm.$u.get(`/api/orders/${id}/status`) //获取支付状态
	const getOrder = params => vm.$u.get('/api/orders', params) //获取我的订单

	// 地址信息
	const getAdd = () => vm.$u.get('/api/address') //获取地址
	const setDefault = params => vm.$u.patch(`/api/address/${params}/default`) //设置默认地址
	const deleteAdd = params => vm.$u.delete(`/api/address/${params}`) //删除地址
	const addList = params => vm.$u.post('/api/address', params) //添加地址
	const getAddDetail = params => vm.$u.get(`/api/address/${params}`) //获取地址详情
	const updateAdd = (id, params) => vm.$u.put(`/api/address/${id}`, params) //获取地址详情
	
	vm.$u.api = {
		index,
		authLogin,
		register,
		loginOut,
		authOss,
		userInfo,
		userChange,
		userAvatar,
		goodsDetail,
		goodsCollect,
		goodsList,
		cartList,
		addCart,
		changeCheck,
		removeCart,
		viewCart,
		subCart,
		pay,
		payStatus,
		getOrder,
		getAdd,
		setDefault,
		deleteAdd,
		addList,
		getAddDetail,
		updateAdd,
		
	}
}
export default {
	install
}
